<template>
<div class="dy-main EAccountChangePassword">
  <div class="dy-header">
    <x-header :right-options="{showMore: false}" :left-options="{preventGoBack: true,backText: ''}" @on-click-back="back" @on-click-more="showMenus = true">E账户密码修改</x-header>
  </div>
  <div class="dy-body">
    <group>
      <cell title="账户号码" :value="requestData.ActNum"></cell>
      <cell title="账户类型" :value="requestData.ActType"></cell>
      <x-input type="password" title="原密码" placeholder="请输入6位数字密码" placeholder-align="right" v-model="testVal.oldPassword.val" text-align="right"></x-input>
      <x-input type="password" title="新密码" placeholder="请输入6位数字密码" placeholder-align="right" v-model="testVal.newPassword.val" text-align="right"></x-input>
      <x-input type="password" title="请确认新密码" placeholder="请输入6位数字密码" placeholder-align="right" v-model="testVal.newPasswordAgain.val" text-align="right" @on-blur="checkPass"></x-input>
      <zx-smscode :sendObj="smsSendObj1" @send-mobile="getSmsMobile" v-model="testVal.smsCode.val" title="验证码" label-width="2.2rem" ></zx-smscode>
    </group>
    <toast v-model="showPositionValue" type="text" width="6rem" :time="800" is-show-mask :text="errormsg" position="middle">{{ errormsg }}</toast>
    <div class="btn">
          <x-button type="primary" @click.native="submit">确认修改</x-button>
    </div>
  </div>
</div>
</template>

<script>
export default{
  data () {
    return {
      clickOne: false, // 点击防重
      errormsg: '',
      showPositionValue: false,
      returnData: '', // 返回数据
      requestData: {
        ActNum: '6229331700000033237', // 账户账号
        ActType: 'Ⅱ类' // 选择账户类型
      },
      testVal: {
        oldPassword: {val: '', type: [{typeName: 'minLen', typeVal: '1', msg: '密码长度不能小于1'}, {typeName: 'specialCharacter', typeVal: '', msg: '输入违法字符'}]},
        newPassword: {val: '', type: [{typeName: 'minLen', typeVal: '1', msg: '密码长度不能小于1'}, {typeName: 'specialCharacter', typeVal: '', msg: '输入违法字符'}]},
        newPasswordAgain: {val: '', type: [{typeName: 'minLen', typeVal: '1', msg: '密码长度不能小于1'}, {typeName: 'specialCharacter', typeVal: '', msg: '输入违法字符'}]},
        smsCode: {val: '', type: [{typeName: 'minLen', typeVal: '1', msg: '验证码长度不能小于1'}, {typeName: 'specialCharacter', typeVal: '', msg: '输入违法字符'}]}
      },
      smsSendObj1: {
        'bussType': '13',
        'sendFlag': '2',
        'clientNo': this.$store.getters.getClientNo,
        'mobile': '',
        'cardNo': ''
      },
      smsMobile: ''
    }
  },
  computed: {
    // getEAccountInfoType () {
    //   return this.$store.getters.getEAccountInfoType
    // }
  },
  methods: {
    getSmsMobile (val) {
      this.smsMobile = val
    },
    checkPass () {
      if (this.testVal.newPassword.val !== this.testVal.newPasswordAgain.val) {
        this.errormsg = '前后输入的密码不一致'
        this.showPositionValue = true
        this.testVal.newPasswordAgain.val = ''
      }
    },
    back () {
      this.$publicFun.goBack(this)
    },
    submit () {
      for (let key in this.testVal) {
        let lObj = this.testVal[key]
        let lRes = this.$publicFun.formCheck(lObj)
        if (!lRes.isOK) {
          this.errormsg = lRes.msg
          this.showPositionValue = true
          return false
        }
      }
      if (this.clickOne) return true
      this.clickOne = true
      this.getData()
    },
    /*
     * 验证短信验证码
     */
    checkSmscode () {
      this.$bridge.callhandler('nativeRequest',
        JSON.stringify({
          'requstSource': 'internetRequest',
          'url': 'mstep.do?act=business',
          'params': {'method_Name': 'checkCode', 'basic_Data': JSON.stringify({'bussType': '13', 'mobile': this.smsMobile, 'smsCode': this.testVal.smsCode.val})}
        }),
        (response) => {
          // alert(response)
          this.clickOne = false
          let rep = JSON.parse(response).data
          if (rep.head.respCode === '000000') {
            return true
          } else {
            this.$bridge.callhandler('showErrorHUD', {
              'type': 'toast',
              'errorMess': rep.head.respMsg
            })
            return false
          }
        })
    },
    getData () {
      this.$bridge.callhandler('nativeRequest',
        JSON.stringify({
          'requstSource': 'internetRequest',
          'url': 'mstep.do?act=business',
          'params': {'method_Name': 'updateBusinessPassword', 'basic_Data': JSON.stringify({'cardNo': this.requestData.ActNum, 'oldPwd': this.testVal.oldPassword.val, 'newPwd': this.testVal.newPassword.val})}
        }),
        (response) => {
          // alert(response)
          let rep = JSON.parse(response).data
          if (rep.head.respCode === '000000') {
            this.errormsg = '密码修改成功'
            this.showPositionValue = true
            this.$router.push({name: 'EAccountEnter'})
          } else {
            this.errormsg = '密码修改失败'
            this.showPositionValue = true
          }
          this.clickOne = false
        })
    }
  }
}
</script>

<style lang="less">
.EAccountChangePassword{
  .btn{
    padding: .32rem .6rem;
  }
}
</style>
